const express = require('express');
const myroute = express.Router()
const mySql = require('../utils/database')
// 接受前端数据
myroute.get('/login', function (request, response) {
    const sql = `SELECT * FROM admin WHERE admin_user='${request.query.username}'&& admin_psd ='${request.query.password}'`
    mySql.query(sql, function (err, data) {
        console.log(err, data);
        if (err) {
            console.log(err);
        } else {
            if (data.length) {
                // 有用户
                response.send('登陆成功')

            } else {
                // 没有用户
                response.send('账号密码错误')
            }
        }
    })

})
myroute.get('/querpasswoed', function (request, response) {
    const sql = `SELECT * FROM admin WHERE admin_user='${request.query.utruename}'`
    mySql.query(sql, function (err, data) {
        console.log(err, data);
        if (err) {
            console.log(err);
        } else {
            if (data.length) {
                // 有用户
                response.send('有此账户')

            } else {
                // 没有用户
                response.send('没有此账户')
            }
        }
    })
})
myroute.get('/quertell', function (request, response) {
    const sql = `SELECT * FROM admin WHERE admin_user='${request.query.utruename}' and admin_tel='${request.query.utruetell}'`
    mySql.query(sql, function (err, data) {
        console.log(err, data);
        if (err) {
            console.log(err);
        } else {
            if (data.length) {
                // 有用户
                response.send('有')

            } else {
                // 没有用户
                response.send('没有此账户')
            }
        }
    })
})
myroute.get('/editpassword', function (request, response) {
    const sql = `UPDATE admin SET admin_psd='${request.query.utruepassword}' WHERE admin_user='${request.query.utruename}'`
    mySql.query(sql, function (err, data) {
        console.log(err, data);
        if (err) {
            console.log(err);
        } else {
            response.send('修改成功')
        }
    })
})
module.exports = myroute